﻿using System.Collections;
using System.Text;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Director : MonoBehaviour
{
    // 单例
    private static Director _singles;
    public static Director Singles { 
        get { 
        return _singles;
        }
    }
    private int _HP = 100;
    public int HP {
        set {
            _HP = value;
            StringBuilder str = new StringBuilder();
            str.Append("LEVEL ");
            str.Append(_levelGame);
            str.Append(" HP : ");
            str.Append(value);
            HPText.text = str.ToString();

            if (_HP <= 0) {
                GAMEOVER.enabled = true;
            } else {
                GAMEOVER.enabled = false;
            }
        }
        get {
            return _HP;
        }
    }
    // 所有生成的怪兽
    public List<Enemy> Enemys = new List<Enemy>();
    // 游戏关卡
    private static int _levelGame = 1;
    // Start is called before the first frame update
    // public GameObject Map;
    private Map _map;
    public Text HPText;
    public Text GAMEOVER;
    private void Awake() {
        DontDestroyOnLoad(this);
        SceneManager.sceneLoaded += OnSceneLoaded;
        SceneManager.sceneUnloaded += OnSceneUnloaded;
        _singles = this;
        
       
    }
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void sendMessToEnemy(string funName) {
        foreach (var item in Enemys)
        {
            item.move();
            // SendMessage(funName, item);
        }
    }
    private void OnSceneLoaded(Scene scene,LoadSceneMode move) {
        _map = GameObject.Find("Map").GetComponent<Map>();

        _map.init(_levelGame);
        // int temp = _HP;
        HP = _HP;//temp;
	    // Debug.Log("场景被加载了");
}
    private void OnSceneUnloaded(Scene scene)
    {
        _levelGame++;
        Enemys.Clear();
        // Debug.Log("场景被销毁了");
    }
}
